﻿using System;
using System.Collections.Generic;
using System.Text;
using Autorun;
using System.Collections.Specialized;

namespace Samples
{
    /// <summary>
    /// This class is used to test chaining tasks
    /// </summary>
    [Serializable]
    public class DebugTask : TaskBase
    {
        #region "Constants"
        private const string DEBUG_STRING = "DebugString";
        private const string CHAINED_PARAMETER = "ChainedParameter";
        #endregion

        #region "Members"
        private string _debugString;
        #endregion

        #region "Overrides"
        protected override void InitializeParameterList()
        {
            Parameters.Add(DEBUG_STRING, this.ToString());
        }

        protected override void PreProcess()
        {
            string msg;

            if ((Parameters[DEBUG_STRING] != null) && (Parameters[DEBUG_STRING].Length != 0))
                _debugString = Parameters[DEBUG_STRING];
            else
                throw new ArgumentNullException(string.Format("The parameter {0} cannot be empty", DEBUG_STRING));

            msg = string.Format("Pre-Processing {1} planned on {2}", DateTime.Now, _debugString, Context.PlannedOn);
            Notify(SeverityLevels.Info, msg);
        }

        protected override void Process()
        {
            string msg;

            msg = string.Format("Processing {1}", DateTime.Now, _debugString);
            Notify(SeverityLevels.Info, msg);
        }

        protected override void PostProcess()
        {
            string msg;
            StringDictionary args;

            msg = string.Format("Post-Processing {1}", DateTime.Now, _debugString);
            Notify(SeverityLevels.Info, msg);

            // === Chain the task ============================================
            args = new StringDictionary();
            args.Add(CHAINED_PARAMETER, "This value has been set");
            args.Add("SomeParameter", "SomeValue");
            // Note: if many records found with values "samples.dll" and "Samples.ChainedTasks"
            // there will be an error. In that case, specify the assembly path also
            ChainTask("samples.dll", "Samples.ChainedTask", args);
        }
        #endregion
    }
}
